package com.openweixin.sheknows.dao.impl;
import org.springframework.stereotype.Repository;

import com.openweixin.sheknows.dao.UserNewScoreDao;
import com.openweixin.sheknows.domain.UserNewScore;
@Repository
public class UserNewScoreDaoImpl extends BaseDaoImpl<UserNewScore, Integer> implements UserNewScoreDao {

	@Override
	public Long getNewScoreCountByUid(Integer uid) {
		String hql = "select count(uns.scoreuid) from UserNewScore uns where uns.pk.user.uid = ?";
		return (Long)getSession().createQuery(hql).setInteger(0, uid).uniqueResult();
	} 
	
	@Override
	public int deleteByUid(Integer uid) {
		String hql = "delete from UserNewScore where pk.user.uid = ?";
		return getSession().createQuery(hql).setInteger(0, uid).executeUpdate();
	}
	
	public UserNewScore getNewScoreByUidAndQid(Integer uid,Integer qid){
		String hql = "from UserNewScore where pk.user.uid = ? and pk.question.qid=?";
		return (UserNewScore) getSession().createQuery(hql).setInteger(0, uid)
				.setInteger(1, qid).uniqueResult();
	}
}
